package com.gmail.dmitryustimov.ms.java7.observer.mod.demo.subj1subsc10event1;

import com.gmail.dmitryustimov.ms.java7.patternslib.observer.SubscriberAction;

import java.math.BigDecimal;

public class Subscriber {

    private String name;
    private Subject subject;
    private BigDecimal sum = BigDecimal.valueOf(0);

    public Subscriber(Subject subject, String name) {
        this.name = name;
        this.subject = subject;
        this.subject.getEventPublisher().subscribe(this.new EventAction());
    }

    private class EventAction implements SubscriberAction<Event> {
        @Override
        public void process(Event event) {
            sum.add(BigDecimal.valueOf(1));
        }
    }
}
